package com.yan.consumer;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.yan.QueueConstants;

/**
 * TODO
 *
 * @Author: 汪焰
 * @Date: 2021/7/4 23:27
 */
public class ConsumerShangHai {
    private static String shangHai = QueueConstants.LogArea.SHANG_HAI.getLevel();

    public static void main(String[] args) throws Exception {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setUri("amqp://root:root@1.116.195.238:5672/%2f");

        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();

        final String queue = channel.queueDeclare().getQueue();

        channel.exchangeDeclare(QueueConstants.exchangeName, BuiltinExchangeType.TOPIC, true, false, null);

        //shangHai.order.error
        //只要routingKey是以 shangHai 开头的，后面不管几个点分单词 都可以接受
        channel.queueBind(queue, QueueConstants.exchangeName, shangHai + ".#");

        channel.basicConsume(queue, (consumerTag, message) -> {
            System.out.println(new String(message.getBody()));
        }, consumerTag -> {
        });

    }
}
